package com.cuzofu.fs.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cuzofu.fs.common.PageUtils;
import com.cuzofu.fs.common.R;
import com.cuzofu.fs.entity.MajorEntity;
import com.cuzofu.fs.service.MajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 专业信息
 *
 * @author cuzofu
 * @email cuzofu@qq.com
 * @date 2020-07-10 08:44:49
 */
@RestController
@RequestMapping("/major")
public class MajorController {
    @Autowired
    private MajorService majorService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = majorService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id) {
        MajorEntity major = majorService.getById(id);

        return R.ok().put("major", major);
    }

    /**
     * 项目专业列表
     */
    @RequestMapping("/infoList/{uid}")
    public R infoList(@PathVariable("uid") String uid) {
        QueryWrapper<MajorEntity> qw = new QueryWrapper<>();
        qw.eq("uid", uid);
        qw.orderByAsc("sort");
        return R.ok().put("majorList", majorService.list(qw));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MajorEntity major) {
        majorService.save(major);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MajorEntity major) {
        majorService.updateById(major);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids) {
        majorService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
